package Solution151_175;

import org.junit.Test;

public class Solution153 {
    public int findMin(int[] nums) {
        int start=0;
        int end=nums.length-1;
        int min= Math.min(nums[start],nums[end]);
        while (start<end){
            min= Math.min(Math.min(nums[start],nums[end]),min);
            int mid=(start+end)/2;
            if(nums[mid]>nums[start]){
                start=mid;
            }else{
                end=mid;
            }
        }

        return min;

    }


    @Test
    public void test(){
        //4567890123
        //12345670
        //01234567
        //34567012
        int[] nums=new int[]{1};
        System.out.println(findMin(nums));
        int[] nums2=new int[]{4,5,6,7,8,9,0,1,2,3};
        System.out.println(findMin(nums2));
        int[] nums3=new int[]{1,2,3,4,5,6,7,0};
        System.out.println(findMin(nums3));
        int[] nums4=new int[]{3,4,5,6,7,0,1,2};
        System.out.println(findMin(nums4));

    }
}
